//
//  HouseViewController.m
//  SheShiDu
//
//  Created by 泉  姜 on 16/6/22.
//  Copyright © 2016年 单剑秋. All rights reserved.
//

#import "HouseViewController.h"
#import "MoveSideView.h"

#import "SideCell.h"
#import "WLColView.h"
#import "NowCell.h"

#import "MessageViewController.h"

#define HEIGHT self.view.frame.size.height
#define WIDTH self.view.frame.size.width
@interface HouseViewController ()<WLColViewDataSource,WLColViewDelegate>

@property(nonatomic,strong)UICollectionView *collectionView;
@property (nonatomic, strong)NSMutableArray *picArr;
@property (nonatomic, strong)MessageViewController *m;
@property (nonatomic, strong) WLColView *vi;

@end

@implementation HouseViewController

- (void)viewWillAppear:(BOOL)animated
{
    _vi.collectionView.contentOffset = CGPointMake(-10, 0);
}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    //    MoveSideView *sideView = [[MoveSideView alloc] initWithFrame:self.view.bounds];
    //    [self.view addSubview:sideView];
    
    self.automaticallyAdjustsScrollViewInsets = NO;
    
//    [self backItem];
    
    self.picArr = [NSMutableArray array];
    for (int i = 1; i < 11; i++) {
        NSString *pic = [NSString stringWithFormat:@"M%d", i];
        [_picArr addObject:[UIImage imageNamed:pic]];
    }
//    NSLog(@"%ld~~~~~", _picArr.count);
    
    self.vi = [[WLColView alloc] initWithFrame:self.view.bounds];
    [self.view addSubview:_vi];
    
    
    SideModel *sideModel = [[SideModel alloc] init];
    sideModel.cellSize = CGSizeMake(CGRectGetWidth(_vi.frame) * 0.9, CGRectGetHeight(_vi.frame) * 0.6);
    sideModel.between = 30;
    sideModel.maxR = 0.2;
    sideModel.initOffSetX = CGRectGetWidth(_vi.frame) / 2 - sideModel.cellSize.width / 2;
    _vi.sideModel = sideModel;
    _vi.dataSource = self;
    _vi.delegate = self;
    [_vi.collectionView registerClass:[NowCell class] forCellWithReuseIdentifier:@"cee"];
    self.m = [[MessageViewController alloc] init];
    
    [self backItem];
}

#pragma mark - colViewDataSource

- (NSInteger)colView:(WLColView *)colView collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 10;
}

- (SideCell *)colView:(WLColView *)colView collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    
    NowCell *cell = (NowCell *)[collectionView dequeueReusableCellWithReuseIdentifier:@"cee" forIndexPath:indexPath];
    cell.dic = nil;
    [cell.imgView setImage:[_picArr objectAtIndex:indexPath.item]];
    [cell.messageButton setImage:[UIImage imageNamed:@"houseMessage"] forState:UIControlStateNormal];
    [cell.messageButton addTarget:self action:@selector(messageAction:) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

- (void)colView:(WLColView *)colView collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    _m.fuck = indexPath.row;
    //    NSLog(@"%ld????", _m.fuck);
    //    NSLog(@"%ld",indexPath.row);
//    [UIView transitionFromView:self.view toView:_m.view duration:0.5 options:UIViewAnimationOptionTransitionFlipFromLeft completion:^(BOOL finished) {
//        
//    }];
}


- (void)backItem
{
    self.navigationController.navigationBar.tintColor = [UIColor blackColor];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"back"] style:UIBarButtonItemStylePlain target:self action:@selector(left:)];
}

- (void)left:(UIBarButtonItem *)left
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)messageAction:(UIButton *)message
{
    MessageViewController *MVC = [[MessageViewController alloc] init];
    CATransition *animation = [CATransition animation];
    animation.duration = 0.4f;
    animation.type = kCATransitionFade;
//    animation.subtype = kCATransitionFromRight;
    [self.navigationController.view.layer addAnimation:animation forKey:nil];
    [self.navigationController pushViewController:MVC animated:NO];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
